package com._520it.member.web.controller;

import com._520it.member.domain.Vip;
import com._520it.member.page.AjaxResult;
import com._520it.member.page.PageResult;
import com._520it.member.query.VipQueryObject;
import com._520it.member.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("vip")
public class VipController {

    @Autowired
    private IVipService vipService;

    @RequestMapping("")
    public String index(){
        return "vip/vip";
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(VipQueryObject qo){

        PageResult result = vipService.queryPage(qo);

        return result;
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Vip vip){
        AjaxResult ajaxResutl = null;
        try {
            if(vip.getId()!=null){
                vipService.updateByPrimaryKey(vip);
                ajaxResutl = new AjaxResult(true,"更新成功!");
            }else{
                vipService.insert(vip);
                ajaxResutl = new AjaxResult(true,"保存成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResutl = new AjaxResult("操作失败");
        }

        return  ajaxResutl;
    }
}
